

/**
 * @author Team 29
 * Stores recieved messages in a queue to be retrieved by the server.
 *
 */
public class RecievedMessages{

	public int head = 0;
	public int size = 0;
	private RecievedMessage[] mq = new RecievedMessage[10];
	
	public RecievedMessages()
	{}
	
	/**
	 * @param rm
	 * adds a recieved message to the queue.
	 */
	public void add(RecievedMessage rm)
	{
		mq[(size + head)%10] = rm;
		size++;
		if(size > 10)
		{
			System.err.println("Recieved Message Queue overflow");
			System.exit(-1);
		}
	}//end add
	
	/**
	 * @return head of the queue.
	 */
	public RecievedMessage grab()
	{
		head++;
		size--;
		return mq[(head - 1)%10];
	}
	
	

}//end class
